import java.util.HashMap;

public class Offer22E {
    public ListNode getKthFromEnd(ListNode head, int k) {
        if (head==null){
            return null;
        }
        HashMap<Integer,ListNode> map=new HashMap<>();
        ListNode now=head;
        int count=0;
        map.put(count,now);
        while (now.next!=null){
            now=now.next;
            map.put(++count,now);
        }
        return map.get(count-k+1);
    }
}

class ListNode{
    int val;
    ListNode next;
    public ListNode(){};
    public ListNode(int x){
        val=x;
    }
    public ListNode(int x,ListNode next){
        val=x;
        this.next=next;
    }
}
